Skip to content

test(command-integrator): write _make_package fixtures as utf-8 bytes for Windows#1123

Closed
danielmeppiel wants to merge 1 commit intomainfrom
fix/windows-utf8-write-text
Closed

test(command-integrator): write _make_package fixtures as utf-8 bytes for Windows#1123
danielmeppiel wants to merge 1 commit intomainfrom
fix/windows-utf8-write-text

Conversation

@danielmeppiel
Copy link
Copy Markdown
Collaborator

TL;DR

Fix Windows-only test failure introduced when _make_package (shared helper at tests/unit/integration/test_command_integrator.py:25) writes fixture content via Path.write_text(content). On Windows the default codec is cp1252, which raises UnicodeEncodeError for the U+E041 tag character that test_critical_security_finding_blocks_write deliberately injects. Switch to write_bytes(content.encode("utf-8")).

Failing run

https://github.com/microsoft/apm/actions/runs/25286532040/job/74131700555 (Build & Test, windows-latest, x86_64).

FAILED tests/unit/integration/test_command_integrator.py::TestCursorCommandPanelFindings::test_critical_security_finding_blocks_write
- UnicodeEncodeError: 'charmap' codec can't encode character '\U000e0041' in position 39
  C:\hostedtoolcache\windows\Python\3.12.10\x64\Lib\encodings\cp1252.py:19
  tests\unit\integration\test_command_integrator.py:37
      (prompts_dir / name).write_text(content)

7366 passed, 1 failed.

Why this is the right fix

The test purposefully injects U+E041 to exercise the post-transform critical-finding gate (the production code is supposed to block this character on the way in, not encode it for storage). The fixture only needs to write the literal bytes to disk for the gate to read back -- so we should NOT round-trip via the platform default text codec.

This matches the canonical fixture pattern already used in this repo whenever bytes-on-disk must equal bytes-in-test (e.g. sha256 integrity helpers in tests/unit/install/test_install_local_bundle.py:68, tests/integration/test_install_local_bundle_e2e.py:64, and tests/unit/bundle/test_local_bundle.py:82 -- the last one fixed in PR #1103). It also sidesteps write_text's Windows \n -> \r\n translation, which the failing trace shows happening in the input string.

Validation

  • Local: uv run --extra dev pytest tests/unit/integration/test_command_integrator.py::TestCursorCommandPanelFindings -x -- 8 passed.
  • Lint: ruff check and ruff format --check on the touched file -- silent.
  • 1-line surgical change in a shared test helper; all other write_text calls in the same file are pure ASCII and remain unchanged.

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

… for Windows

The _make_package helper used by TestCursorCommandPanelFindings calls
Path.write_text(content), which on Windows defaults to the cp1252
encoder and raises UnicodeEncodeError on the U+E041 tag character that
test_critical_security_finding_blocks_write deliberately injects to
exercise the post-transform critical-finding gate.

Switch to write_bytes(content.encode('utf-8')), matching the canonical
pattern already used in this repo for fixture content that must round-
trip exactly (sha256 integrity helpers in tests/unit/install/ and
tests/unit/bundle/). This also avoids write_text's Windows newline
translation, so the bytes on disk match the literal test input.

Failing run: https://github.com/microsoft/apm/actions/runs/25286532040
job 74131700555 (Build & Test, windows-latest).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 3, 2026 18:10
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a Windows-only unit test failure in the command integrator test suite by writing prompt fixture files as raw UTF-8 bytes instead of using the platform-default text encoding.

Changes:

  • Update the shared _make_package test helper to write fixture content via Path.write_bytes(content.encode("utf-8")) to avoid Windows cp1252 encoding errors and newline translation.
Show a summary per file
File Description
tests/unit/integration/test_command_integrator.py Switch fixture file writes to UTF-8 bytes to make the security-finding test deterministic on Windows.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants